﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace EIA.SLClient.Utility.Converters
{
    public class GenericConverter<T,TB> : IValueConverter 
    {
        public GenericConverter(Func<T, object, TB> convert)
        {
            _convert = convert;
        }
        public GenericConverter(Func<T, object, TB> convert, Func<TB, object, T> convertback)
        {
            _convert = convert;
            _convertback = convertback;
        }

        protected Func<T, object, TB> _convert = null;
        protected Func<TB, object, T> _convertback = null;

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (_convert != null)
            {
                return _convert((T)value, parameter);
            }
            throw new NotImplementedException();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (_convertback != null)
            {
                return _convertback((TB)value, parameter);
            }
            throw new NotImplementedException();
        }
    }
}
